﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BWindingMachine
{
    public partial class KeyBoardForm : Form
    {
        private bool _IsOk = false;
        private string _RetVal = "";

        public bool IsOk
        {
            get
            {
                return _IsOk;
            }
        }

        public string ReturnValue
        {
            get
            {
                return _RetVal;
            }
        }

        public KeyBoardForm()
        {
            InitializeComponent();
            this.Location = new Point((Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2);
        }

        private void btn_Clear_Click(object sender, EventArgs e)
        {
            txt_InputValue.Text = "";
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            _IsOk = false;
            this.Close();
        }

        private void btn_Confirm_Click(object sender, EventArgs e)
        {
            if (txt_InputValue.Text.Length > 0)
            {

                _IsOk = true;
                _RetVal = txt_InputValue.Text.Trim();
                this.Close();
            }
            else
            {
                MessageBox.Show("请输入数据！");
            }
        }

        private void btn_Number_Click(object sender, EventArgs e)
        {
            string str = txt_InputValue.Text.Trim();
            string val = ((Button)sender).Text;
            if (val == "-")
            {
                if (str.Length == 0)
                {
                    txt_InputValue.Text = str + val;
                }
            }
            else
            {
                if (val == ".")
                {
                    if (str.Length > 0)
                    {
                        if (!str.Contains(val))
                        {
                            txt_InputValue.Text = str + val;
                        }
                    }
                }
                else
                {
                    txt_InputValue.Text = str + val;
                }
            }
        }
    }
}